#ifndef PM_EVENTS_H_INCLUDED
#define PM_EVENTS_H_INCLUDED

#include <wx/event.h>

template <typename T>
class pmEvent : public wxNotifyEvent
{
	T  m_content;
	
public:
	typedef void (wxEvtHandler::*Function)(pmEvent<T>&);

public:
	pmEvent(wxEventType commandType, const T& t, int id = 0)
	: wxNotifyEvent(commandType, id)
	, m_content(t)
	{
	}

	wxEvent* Clone() const
	{
		return new pmEvent<T>(*this);
	}

	const T& GetContent()
	{
		return m_content;
	}
};

#define pmEventHandler(type, func) \
    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(pmEvent<type>::Function, &func)


#define pmConnect(evtType, type, function) \
	wxTheApp->Connect(evtType, pmEventHandler(type, function), NULL, this)

#define pmConnectNotify(evtType, function) \
	wxTheApp->Connect(evtType, wxNotifyEventHandler(function), NULL, this)

#define pmDisconnect(evtType, type, function) \
	wxTheApp->Disconnect(evtType, pmEventHandler(type, function), NULL, this)

#define pmDisconnectNotify(evtType, function) \
	wxTheApp->Disconnect(evtType, wxNotifyEventHandler(function), NULL, this)


DECLARE_EVENT_TYPE(pmEVT_CONNECT_EVENTS, wxID_ANY)

DECLARE_EVENT_TYPE(pmEVT_PROJECT_LOADED, wxID_ANY)

DECLARE_EVENT_TYPE(pmEVT_WORK_REQUEST_ADDED,   wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_WORK_REQUEST_UPDATED, wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_WORK_REQUEST_REMOVED, wxID_ANY)

DECLARE_EVENT_TYPE(pmEVT_COST_ADDED,   wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_COST_UPDATED, wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_COST_REMOVED, wxID_ANY)

DECLARE_EVENT_TYPE(pmEVT_TAG_ADDED,   wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_TAG_UPDATED, wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_TAG_REMOVED, wxID_ANY)

DECLARE_EVENT_TYPE(pmEVT_TASK_ADDED,   wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_TASK_UPDATED, wxID_ANY)
DECLARE_EVENT_TYPE(pmEVT_TASK_REMOVED, wxID_ANY)


#endif // PM_EVENTS_H_INCLUDED
